package com.micolor.logr.demo.service.log.dict;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.micolor.logr.demo.entity.TenantInfo;
import com.micolor.logr.demo.mapper.TenantMapper;
import com.micolor.logr.runtime.entity.LogFieldEnum;
import com.micolor.logr.runtime.interfaces.LogFieldEnumInitInterface;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author EvanGe
 * @Type TenantDictServiceImpl.java
 * @Desc
 * @date 2024/7/9 16:36
 */
@Component
@Slf4j
public class TenantDictServiceImpl  implements LogFieldEnumInitInterface {

    @Autowired
    private TenantMapper tenantMapper;
    /**
     * 获取枚举类型定义的数据集合
     *
     * @param enumTypeOrParam
     * @return
     */
    @Override
    public List<LogFieldEnum> getLogFieldEnum(Object enumTypeOrParam) {
        Map<String,Object> map = (Map<String, Object>)enumTypeOrParam;
        Long tenantId= Long.parseLong(map.get("tenantId").toString());
        List<LogFieldEnum> logFieldEnums = new ArrayList<>();
        LambdaQueryWrapper<TenantInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(TenantInfo::getTenantId,tenantId);
        TenantInfo tenantInfo = tenantMapper.selectOne(queryWrapper);
        LogFieldEnum logFieldEnum = new LogFieldEnum();
        logFieldEnum.setKey(tenantInfo.getTenantId().toString());
        logFieldEnum.setValue(tenantInfo.getTenantName());
        logFieldEnums.add(logFieldEnum);
        return logFieldEnums;
    }
}
